﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	x:Class="Faust.Andrew.MTG.Player.CardListControl"
	x:Name="UserControl" MinWidth="275" AllowDrop="True" PreviewDrop="CardList_PreviewDrop">
	<UserControl.Resources>
		<DataTemplate x:Key="CardItemTemplate">
			<Grid ToolTip="{Binding CardText, Mode=OneWay}" Margin="5,0" MouseEnter="Grid_MouseEnter" PreviewMouseLeftButtonDown="CardList_PreviewMouseLeftButtonDown" PreviewMouseMove="CardList_PreviewMouseMove" PreviewMouseRightButtonDown="CardList_PreviewMouseRightButtonDown">
				<Grid.LayoutTransform>
					<TransformGroup>
						<ScaleTransform ScaleX="{Binding Value, ElementName=sizeSlider, Mode=OneWay}" ScaleY="{Binding Value, ElementName=sizeSlider, Mode=OneWay}"/>
						<SkewTransform/>
						<RotateTransform/>
						<TranslateTransform/>
					</TransformGroup>
				</Grid.LayoutTransform>
				<Image Source="{Binding ImageSource, Mode=OneWay}" MinWidth="226" MinHeight="331"/>
			</Grid>
		</DataTemplate>
		<ItemsPanelTemplate x:Key="HandItemsPanel">
			<StackPanel x:Name="spCards" IsItemsHost="True" Orientation="Horizontal" SizeChanged="spCards_SizeChanged"/>
		</ItemsPanelTemplate>
		<Style x:Key="CardItemLayoutTemplate" TargetType="{x:Type ListBoxItem}">
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
			<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
			<Setter Property="Padding" Value="2,0,0,0"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ListBoxItem}">
						<Border x:Name="Bd" SnapsToDevicePixels="true" Padding="{TemplateBinding Padding}">
							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsSelected" Value="true">
								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
							</Trigger>
							<MultiTrigger>
								<MultiTrigger.Conditions>
									<Condition Property="IsSelected" Value="true"/>
									<Condition Property="Selector.IsSelectionActive" Value="false"/>
								</MultiTrigger.Conditions>
								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
							</MultiTrigger>
							<Trigger Property="IsEnabled" Value="false">
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</UserControl.Resources>

	<Grid x:Name="LayoutRoot">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		<Slider x:Name="sizeSlider" d:LayoutOverrides="Height" Value="1" Maximum="2"/>
		<ListBox x:Name="lbHand" Background="{x:Null}" ItemsSource="{Binding CardList, ElementName=UserControl, Mode=TwoWay}" ItemTemplate="{DynamicResource CardItemTemplate}" ItemsPanel="{DynamicResource HandItemsPanel}" SelectionMode="Extended" BorderBrush="{x:Null}" Foreground="White" VerticalContentAlignment="Center" Grid.Row="1" MouseDoubleClick="Cards_MouseDoubleClick">
			<ListBox.ContextMenu>
				<ContextMenu>
					<MenuItem x:Name="mnuPlay" Header="_Play" Click="mnuPlay_Click"/>
					<MenuItem x:Name="mnuPlayFaceDown" Header="Play _Face Down" Click="mnuPlayFaceDown_Click"/>
					<MenuItem Header="Show Cards" Click="Cards_Show" />
					<MenuItem Header="_Send to Hand" Click="Card_ToHand" />
					<MenuItem Header="Send to _Graveyard" Click="Card_ToGraveyard" />
					<MenuItem Header="Send to _Workspace" Click="Card_ToWorkspace" />
					<MenuItem Header="Send to _Deck">
						<MenuItem Header="_Top" Click="Card_ToDeckTop"/>
						<MenuItem Header="_Bottom" Click="Card_ToDeckBottom"/>
						<MenuItem Header="_Random" Click="Card_ToDeckRandom"/>
						<MenuItem Header="# From Top" Click="Card_ToDeckFromTop"/>
						<MenuItem Header="# From Bottom" Click="Card_ToDeckFromBottom"/>
					</MenuItem>
				</ContextMenu>
			</ListBox.ContextMenu>
		</ListBox>
	</Grid>
</UserControl>